<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			input[type="text"]{height:30px; margin-bottom: 5px;}
			form:before{ background: none !important; border: none !important;}
			.mui-switch:before {content: '无'; color: #999;}
			.mui-switch.mui-active:before {content: '有'; color: #fff;}
			input{border-width:0; text-align: right; font-size:14px; line-height: 26px;}
			div{line-height: 26px;}
			.bottom_soild{border-bottom: 1px solid #DDDDDD; line-height: 26px;}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
			#Popup {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}
			.mui-popover{
				width: 300px;
			}
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.mui-switch{
				border-color: #007AFF;
				background-color: #007AFF;
				border-width: 1px;
				width: 80px;
			}
			#mySwitchx:before{content: '选择';}
			#mySwitchx.mui-active:before{content: '填写'; left: 15px;}
			.mui-switch:before {content: '掌握'; color: #fff; right: 15px;}
			.mui-switch.mui-active:before {content: '未掌握'; color: #fff; left: 5px;}
			.mui-switch.mui-active {
				border-color: #fd933b;
				background-color: #fd933b;
			}
			.popover-cont ul{
				margin-top: 5px; 
				margin: 0; 
				padding: 0; 
				list-style: none; 
				background: #ffffff;
			}
			.table{
				width: 100%;
			}
			.thead{
				width: 100%;
				border: 1px solid #007AFF;
			}
			.thead tr{
				 width: 100%; 
				 background-color: #007AFF;
				 height: 20px;
			}
			.thead tr th{
				color: #ffffff;
				border-right: 1px solid #ffffff;
				text-align: center;
				font-family: "microsoft yahei";
				font-size: 14px;
				line-height: 20px;
			}
			.tbody{
				width: 100%;
				border: 1px solid #007AFF;
			}
			.tbody tr{
				 width: 100%; 
				 height: 20px;
			}
			.tbody tr td{
				color: #000;
				border: 1px solid #007AFF;
				text-align: center;
				font-family: "microsoft yahei";
				font-size: 14px;
				line-height: 20px;
			}
			.div-tab{
				width: 100%; 
				height: 200px; 
				overflow-y: scroll;
			}
			.div-tab::-webkit-scrollbar {
				display: none;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">其它信息</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<div style="margin-left:0.9rem; line-height:35px;">健康教育及培训</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float:left; width:100%; margin-top:6px;">
								<div style="float:left; font-size: 16px; line-height: 26px;">取药时间</div>
								<a data-options='{"type":"date"}' class="btn mui-navigate-right" style="padding-right: 20px; float: right;">
									<input  id='result0' class="ui-alert"  placeholder="请选择" style="width:80px; float: right; color:#000; line-height: 26px;"/>
								</a>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float:left; width:100%; margin-top:6px;">
								<div style="float:left; font-size: 16px;">取药地点</div>
								<input id="ad" style="width:50%; float:right; text-align: right;" class="ui-alert bottom_soild"  placeholder="请输入地点"/>								
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">服药记录卡填写</div>
							<div class="mui-switch" id="mySwitch1">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">服药方法及药品存放</div>
							<div class="mui-switch" id="mySwitch2">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">肺结核治疗疗程</div>
							<div class="mui-switch" id="mySwitch3">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">不规律服药危害</div>
							<div class="mui-switch" id="mySwitch4">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">服药后不良反应及处理</div>
							<div class="mui-switch" id="mySwitch5">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">治疗期间复诊查痰</div>
							<div class="mui-switch" id="mySwitch6">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">外出期间如何坚持服药</div>
							<div class="mui-switch" id="mySwitch7">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">生活习惯及注意事项</div>
							<div class="mui-switch" id="mySwitch8">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 16px;">密切接触者检查</div>
							<div class="mui-switch" id="mySwitch9">
							  <div class="mui-switch-handle"></div>
							</div>
						</li>
					</div>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self1 = localStorage.getItem("name")
			var dataold = JSON.parse(self1)
			var obj = dataold.obj
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview();
					listdata = self.data;
					visitId = self.visitdata;
					selfdata = JSON.parse(listdata);
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
					tbId = self.arcid;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					for(var i=0; i<second.length; i++){
						if(second[i].questionId == "912"){
							//取药时间
							var datev = new Date(second[i].answer);
							var yearv=datev.getFullYear(); 
							var monthv=datev.getMonth()+1;
							var dayv=datev.getDate();
								monthv =(monthv<10 ? "0"+monthv:monthv); 
								dayv =(dayv<10 ? "0"+dayv:dayv); 
							medicinetime = (yearv.toString()+'-'+monthv.toString()+'-'+dayv.toString());
							document.getElementById("result0").value = medicinetime;
						}
						if(second[i].questionId == "911"){
							document.getElementById("ad").value = second[i].answer;
						}
						if(second[i].questionId == "913"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch1").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch1").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "914"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch2").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch2").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "915"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch3").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch3").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "916"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch4").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch4").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "917"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch5").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch5").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "918"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch6").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch6").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "919"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch7").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch7").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "920"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch8").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch8").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "921"){
							if(second[i].answerId == "2"){
								document.getElementById("mySwitch9").classList.add('mui-active');
							}else{
								document.getElementById("mySwitch9").classList.remove('mui-active');
							}
						}
					}
				}
			})
			//赋值
			var id = 0;
			var visitId= 0;
			var ehrId = "";
			var tbId ="";//肺结核专档id
			var createDate = "";
			var createUserid = obj.id;
			var modifyDate = "";
			var modifyUserid = obj.id;
			var medicinetime = "";
				mui.init()
				(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							if(i == 0){
								var optionsJson = this.getAttribute('data-options') || '{}';
								var options = JSON.parse(optionsJson);
								var id = this.getAttribute('id');
								_self.picker = new $.DtPicker(options);
								_self.picker.show(function(rs) {
									$('#result'+i)[0].value = rs.text;
									_self.picker.dispose();
									_self.picker = null;
								});
							}else{
								var optionsJson = this.getAttribute('data-options') || '{}';
								var options = JSON.parse(optionsJson);
								var id = this.getAttribute('id');
								/*
								 * 首次显示时实例化组件
								 * 示例为了简洁，将 options 放在了按钮的 dom 上
								 * 也可以直接通过代码声明 optinos 用于实例化 DtPicker
								 */
								_self.picker = new $.DtPicker(options);
								_self.picker.show(function(rs) {
									/*
									 * rs.value 拼合后的 value
									 * rs.text 拼合后的 text
									 * rs.y 年，可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
									 * rs.m 月，用法同年
									 * rs.d 日，用法同年
									 * rs.h 时，用法同年
									 * rs.i 分（minutes 的第二个字母），用法同年
									 */
									result.value = rs.text;
									/* 
									 * 返回 false 可以阻止选择框的关闭
									 * return false;
									 */
									/*
									 * 释放组件资源，释放后将将不能再操作组件
									 * 通常情况下，不需要示放组件，new DtPicker(options) 后，可以一直使用。
									 * 当前示例，因为内容较多，如不进行资原释放，在某些设备上会较慢。
									 * 所以每次用完便立即调用 dispose 进行释放，下次用时再创建新实例。
									 */
									_self.picker.dispose();
									_self.picker = null;
								});
							}
						}
						
					}, false);
				});
			})(mui);
			//开关事件
			mui('.mui-switch')['switch']()
			
			//切换
			var onoff1 ="1"
			var onoff2 ="1"
			var onoff3 ="1"
			var onoff4 ="1"
			var onoff5 ="1"
			var onoff6 ="1"
			var onoff7 ="1"
			var onoff8 ="1"
			var onoff9 ="1"
			document.getElementById("mySwitch1").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff1 ="2"
				}else{
					onoff1 ="1"
				}
			})
			document.getElementById("mySwitch2").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff2 ="2"
				}else{
					onoff2 ="1"
				}
			})
			document.getElementById("mySwitch3").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff3 ="2"
				}else{
					onoff3 ="1"
				}
			})
			document.getElementById("mySwitch4").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff4 ="2"
				}else{
					onoff4 ="1"
				}
			})
			document.getElementById("mySwitch5").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff5 ="2"
				}else{
					onoff5 ="1"
				}
			})
			document.getElementById("mySwitch6").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff6 ="2"
				}else{
					onoff6 ="1"
				}
			})
			document.getElementById("mySwitch7").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff7 ="2"
				}else{
					onoff7 ="1"
				}
			})
			document.getElementById("mySwitch8").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff8 ="2"
				}else{
					onoff8 ="1"
				}
			})
			document.getElementById("mySwitch9").addEventListener("toggle",function(event){
				if(event.detail.isActive){
					onoff9 ="2"
				}else{
					onoff9 ="1"
				}
			})
			//提交
			function submit(){
				medicinetime = $('#result0')[0].value+" 00:00:00";//取药时间
				if($("#mySwitch1").hasClass("mui-active")){
					onoff1 = "2";
				}else{
					onoff1 = "1";
				}
				if($("#mySwitch2").hasClass("mui-active")){
					onoff2 = "2";
				}else{
					onoff2 = "1";
				}
				if($("#mySwitch3").hasClass("mui-active")){
					onoff3 = "2";
				}else{
					onoff3 = "1";
				}
				if($("#mySwitch4").hasClass("mui-active")){
					onoff4 = "2";
				}else{
					onoff4 = "1";
				}
				if($("#mySwitch5").hasClass("mui-active")){
					onoff5 = "2";
				}else{
					onoff5 = "1";
				}
				if($("#mySwitch6").hasClass("mui-active")){
					onoff6 = "2";
				}else{
					onoff6 = "1";
				}
				if($("#mySwitch7").hasClass("mui-active")){
					onoff7 = "2";
				}else{
					onoff7 = "1";
				}
				if($("#mySwitch8").hasClass("mui-active")){
					onoff8 = "2";
				}else{
					onoff8 = "1";
				}
				if($("#mySwitch9").hasClass("mui-active")){
					onoff9 = "2";
				}else{
					onoff9 = "1";
				}
				var dataobj=[
					//取药地点
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"911",
					"answerId":"0",
					"answer":mui("#ad")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//取药时间
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"912",
					"answerId":"0",
					"answer":medicinetime,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//服药记录
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"913",
					"answerId":onoff1,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//服药方法
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"914",
					"answerId":onoff2,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//治疗疗程
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"915",
					"answerId":onoff3,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//不规律服药危害
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"916",
					"answerId":onoff4,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//不良反应处理
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"917",
					"answerId":onoff5,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//治疗期间
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"918",
					"answerId":onoff6,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//外出期间
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"919",
					"answerId":onoff7,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//生活习惯
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"920",
					"answerId":onoff8,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//密切接触者
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"921",
					"answerId":onoff9,
					"answer":null,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid}
				]	
					$.ajax({
						type: 'post',
						url:getRequestUrl.url+"/mobile/ehr/TbVisitAddition/addOrUpdate",
						data:JSON.stringify(dataobj),
						dataType:"json",
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							if(data.status==1){
								alert("提交成功");
								mui.openWindow({
									url: 'follow_up_add.html', 
									id:'follow_up_add',
									extras:{
										
									}
								});
							}else{
								alert(data.message);
							}
						},
						error:function(xhr,type,errorThrown){
							
						}
					})
			}
		</script>
	</body>

</html>